#ifndef     __PACKET_H
#define     __PACKET_H

extern "C" {
#include <libavcodec/packet.h>
}
#include "../../utils/nocopyable.h"
#include <utility>

struct Packet : private utils::NoCopyable {

    Packet(AVPacket *pkt = nullptr) : packet(pkt) {
    }

    Packet(Packet &&other) {
        packet = other.packet;
        other.packet = nullptr;
    }

    Packet& operator=(Packet &&other) {
        std::swap(packet, other.packet);
        return *this;
    }

    ~Packet() {
        if (packet != nullptr) {
            av_packet_free(&packet);
        }
    }

    void unref() {
        av_packet_unref(packet);
    }

    inline AVPacket* operator->() {
        return packet;
    }

    inline operator bool() const {
        return packet != nullptr;
    }

    AVPacket *packet;
};

#endif
